﻿/*
 * This file is part of CommunitySettlers.
 *
 * CommunitySettlers is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.

 * CommunitySettlers is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with CommunitySettlers.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * Author: Christoph Husse
 * 
 * Also checkout our homepage: http://communitysettlers.codeplex.com/
 */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SettlersEngine
{
    internal partial class RuntimeGrid
    {
        private class RuntimeGridCell : NativeEngine.IAStarNode
        {
            private IPositionProvider m_FixedObject = null;

            public IResourceObject Resource { get; set; }
            public GroundType Type { get; internal set; }
            public byte Height { get; internal set; }
            public WallType Wall { get; internal set; }
            public RuntimeGrid Grid { get; private set; }
            public int X { get; private set; }
            public int Y { get; private set; }

            public int WallValue
            {
                get
                {
                    return (FixedObject != null) ? 1 : 0;
                }
            }

            public Boolean IsWalkable(IMovableObject inMovable)
            {
                return WallValue == 0;
            }

            internal RuntimeGridCell(
                RuntimeGrid inParent,
                int inX,
                int inY)
            {
                Grid = inParent;
                X = inX;
                Y = inY;
            }

            public IPositionProvider FixedObject
            {
                get { return m_FixedObject; }
                set
                {
                    if ((value != null) && (m_FixedObject != null))
                        throw new InvalidOperationException("There is already an object attached to this cell.");

                    m_FixedObject = value;
                }
            }
        }
    }
}
